package 剑指offer;

public class 二叉树搜索树的第k个节点 {
    public class TreeNode{
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
        public TreeNode(int val){
            this.val = val;
        }
    }
    public class Solution{

        int result = -1;
        int count = 0;
        //中序遍历先将二叉树升序排序
        public int KthNode (TreeNode proot ,int k){

            if (proot == null || k<=0) return -1;
            //向左往下遍历
            KthNode(proot.left,k);
            ++count;
            if (count == k){
                return result = proot.val;
            }
            KthNode(proot.right,k);
            return  result;
        }
    }
}
